package scuba.DiveBuddy.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import scuba.DiveBuddy.Class.LogEntry;
import scuba.DiveBuddy.Enums.PressureGroupEnum;
import scuba.DiveBuddy.R;

/**
 * @author Alex Anderson
 * @version 1.0
 * @since {26/02/14}
 */
public class HistoryEntriesArrayAdapter extends ArrayAdapter<LogEntry> {
    private final Context context;
    private final LogEntry[] entries;

    public HistoryEntriesArrayAdapter(Context context, LogEntry[] entries) {
        super(context, R.layout.component_listitem_history, entries);
        this.context = context;
        this.entries = entries;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.component_listitem_history, parent, false);

        LogEntry currentLog = entries[entries.length - (position + 1)];

        TextView txtV = (TextView)row.findViewById(R.id.diveNumber);
        txtV.setText(currentLog.getDiveNumber() + "");

        txtV = (TextView)row.findViewById(R.id.header);
        txtV.setText(currentLog.getDiveHeader());

        txtV = (TextView)row.findViewById(R.id.desc);
        txtV.setText(currentLog.getShortDescription());

        txtV = (TextView)row.findViewById(R.id.divePG);
        txtV.setText(currentLog.getPressureGroup().toString());

        return row;
    }
}
